package edu.pku.sei.modeler.model.notation.shape;

import org.w3c.dom.Element;

import edu.pku.sei.gefcommon.descriptor.annotation.FieldProperty;
import edu.pku.sei.modeler.model.notation.core.NotationPackage;
import edu.pku.sei.modeler.model.notation.shape.extradata.CornerRectangleData;
import edu.pku.sei.modeler.model.notation.shape.extradata.ExtraData;
import edu.pku.sei.modeler.model.notation.shape.extradata.RoundedRectangleData;
import edu.pku.sei.modeler.model.notation.shape.extradata.TriangleData;
import edu.pku.sei.modeler.model.xml.XMLUtility;

public class Polygon extends Shape {
	public static final int RECTANGLE = 0;
	public static final int TRIANGLE = 1;
	public static final int DIAMOND = 2;
	public static final int CORNERRECTANGLE = 3;
	public static final int ROUNDEDRECTANGLE = 4;
	public static final int COSTUMPOLYGON = 5;

	
	private int type;
	
	protected Polygon(){
		super();
		type = RECTANGLE;
		extraData = null;
	}
	
	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}
	@FieldProperty(catalog="Extra",name="ExtraData",id="SHAPE_EXTRA")
	private ExtraData extraData ;
	public ExtraData getExtraData(){
		return extraData;
	}
	
	static public Polygon createRectangle(){
		Polygon p = new Polygon();
		p.setType(RECTANGLE);
		return p;
	}
	static public Polygon createDiamond(){
		Polygon p = new Polygon();
		p.setType(DIAMOND);
		return p;
		
	}
	static public Polygon createTriangle(){
		Polygon p = new Polygon();
		p.setType(TRIANGLE);
		p.extraData = new TriangleData(p);
		return p;
	}
	
	static public Polygon createCornerRectangle(){
		Polygon p = new Polygon();
		p.setType(CORNERRECTANGLE);
		p.extraData = new CornerRectangleData(p);
		return p;
	}
	static public Polygon createRoundedRectangle(){
		Polygon p = new Polygon();
		p.setType(ROUNDEDRECTANGLE);
		p.extraData = new RoundedRectangleData(p);
		return p;
	}
	//add by fengchao
	public void serialize(Element root) {
		super.serialize(root);
		XMLUtility.xmlInstance.serializeAttribute(root, NotationPackage.POLYGON_TYPE, type);
		XMLUtility.xmlInstance.serializeNode(root, NotationPackage.POLYGON_EXTRADATA, extraData);
	}
	public void deSerialize(Element root) {
		super.deSerialize(root);
		this.type = XMLUtility.xmlInstance.deSerializeInt(root, NotationPackage.POLYGON_TYPE);
		extraData = (ExtraData) XMLUtility.xmlInstance.deSerializeNode(root, NotationPackage.POLYGON_EXTRADATA,this);
		
	}
	//end add

}
